package com.liuguang.rabbitmq.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * @ClassName: MyReturnCallback
 * @Description：当消息发送到broker未被绑定到队列的时候会调用该消息
 * @Author: wanghr
 * Date: 11:25 AM 2020/10/16
 * Version: 1.0
 */
@Component
public class MyReturnCallback implements RabbitTemplate.ReturnCallback {
    private static final Logger logger = LoggerFactory.getLogger(MyReturnCallback.class);

    @Override
    public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        String messageId = message.getMessageProperties().getMessageId();
        logger.info("消息：{}，根据Routing key：{} 绑定到队列成功？：{}", messageId, routingKey, replyText);
    }
}
